package nl.hva.three2learn.model;

import java.io.Serializable;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
@Table(name = "course_period")
public final class CoursePeriod implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = -5174323291454015998L;

	@Id
	@GeneratedValue
	@Column(name = "id")
	private long id;

	@ManyToOne
	@JoinColumn(name = "period_id", referencedColumnName = "course_id")
	private Course course;

	@Column(name = "period_start")
	private Date start;

	@Column(name = "period_end")
	private Date end;
	
	@OneToMany
	@LazyCollection(LazyCollectionOption.FALSE)
	private List<User> users;

	public CoursePeriod() {
		this.users = new LinkedList<User>();
	}

	public CoursePeriod(Course course, Date start, Date end) {
		this.course = course;
		this.start = start;
		this.end = end;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public Course getCourse() {
		return course;
	}

	public void setCourse(Course course) {
		this.course = course;
	}

	public Date getStart() {
		return start;
	}

	public void setStart(Date start) {
		this.start = start;
	}

	public Date getEnd() {
		return end;
	}

	public void setEnd(Date end) {
		this.end = end;
	}

	public List<User> getUsers() {
		return users;
	}

	public void setUsers(List<User> users) {
		this.users = users;
	}
}
